package com.party.core.service.logistics.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.logistics.WlLogisticsTraceReadDao;
import com.party.core.dao.write.logistics.WlLogisticsTraceWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.logistics.WlLogisticsTrace;
import com.party.core.service.logistics.IWlLogisticsTraceService;
import com.sun.istack.NotNull;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * @Author: Administrator.
 * @Description: 物流追踪信息
 * @Date:Created in 2017/9/25 0025 上午 11:32.
 */
@Service
public class WlLogisticsTraceService implements IWlLogisticsTraceService {
    @Autowired
    private WlLogisticsTraceReadDao wlLogisticsTraceReadDao;
    @Autowired
    private WlLogisticsTraceWriteDao wlLogisticsTraceWriteDao;

    /**
     * 商城物流插入
     *
     * @param wlLogisticsTrace 商城物流
     * @return 插入编号
     */
    @Override
    public String insert(WlLogisticsTrace wlLogisticsTrace) {
        BaseModel.preInsert(wlLogisticsTrace);
        boolean result = wlLogisticsTraceWriteDao.insert(wlLogisticsTrace);
        if (result) {
            return wlLogisticsTrace.getId();
        }
        return null;
    }

    /**
     * 更新商城物流
     *
     * @param wlLogisticsTrace 商城物流
     * @return 更新结果（true/false）
     */
    @Override
    public boolean update(WlLogisticsTrace wlLogisticsTrace) {
        wlLogisticsTrace.setUpdateDate(new Date());
        return wlLogisticsTraceWriteDao.update(wlLogisticsTrace);
    }

    /**
     * 逻辑删除商城物流
     *
     * @param id 实体主键
     * @return 删除结果（true/false）
     */
    @Override
    public boolean deleteLogic(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return wlLogisticsTraceWriteDao.deleteLogic(id);
    }

    /**
     * 物理删除商城物流
     *
     * @param id 实体主键
     * @return 删除结果（true/false）
     */
    @Override
    public boolean delete(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return wlLogisticsTraceWriteDao.delete(id);
    }

    /**
     * 批量逻辑删除
     *
     * @param ids 主键集合
     * @return 删除结果（true/false）
     */
    @Override
    public boolean batchDeleteLogic(@NotNull Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return wlLogisticsTraceWriteDao.batchDeleteLogic(ids);
    }

    /**
     * 批量物理删除
     *
     * @param ids 主键集合
     * @return 删除结果（true/false）
     */
    @Override
    public boolean batchDelete(@NotNull Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return wlLogisticsTraceWriteDao.batchDelete(ids);
    }

    /**
     * 获取商城物流
     *
     * @param id 主键
     * @return 商城物流
     */
    @Override
    public WlLogisticsTrace get(String id) {
        return wlLogisticsTraceReadDao.get(id);
    }

    /**
     * 分页查询
     *
     * @param wlLogisticsTrace 商城物流
     * @param page             分页信息
     * @return 商城物流列表
     */
    @Override
    public List<WlLogisticsTrace> listPage(WlLogisticsTrace wlLogisticsTrace, Page page) {
        return wlLogisticsTraceReadDao.listPage(wlLogisticsTrace, page);
    }

    /**
     * 查询所有商城物流
     *
     * @param wlLogisticsTrace 商城物流
     * @return 商城物流列表
     */
    @Override
    public List<WlLogisticsTrace> list(WlLogisticsTrace wlLogisticsTrace) {
        return wlLogisticsTraceReadDao.listPage(wlLogisticsTrace, null);
    }

    @Override
    public List<WlLogisticsTrace> batchList(@NotNull Set<String> ids, WlLogisticsTrace wlLogisticsTrace, Page page) {
        return null;
    }

    @Override
    public List<WlLogisticsTrace> findByLogisticsId(String logisticsId) {
        return wlLogisticsTraceReadDao.findByLogisticsId(logisticsId);
    }

    @Override
    public WlLogisticsTrace getBestNewTrace(String logisticsId) {
        return wlLogisticsTraceReadDao.getBestNewTrace(logisticsId);
    }

    @Override
    public void deleteByLogisticsId(String logisticsId) {
        wlLogisticsTraceWriteDao.deleteByLogisticsId(logisticsId);
    }
}
